Skip to content

GH-49538: [C++][FlightRPC][ODBC] Use static linkage in Windows FlightSQL ODBC driver#49585

Open
amoeba wants to merge 39 commits into
apache:mainfrom
amoeba:flight-sql-odbc-static
Open

GH-49538: [C++][FlightRPC][ODBC] Use static linkage in Windows FlightSQL ODBC driver#49585
amoeba wants to merge 39 commits into
apache:mainfrom
amoeba:flight-sql-odbc-static

Conversation

@amoeba

@amoeba amoeba commented Mar 24, 2026

Copy link
Copy Markdown
Member

Rationale for this change

The FlightSQL ODBC driver was previously using dynamic linkage for the Arrow deps it relies on. This worked but prevented a challenge for code signing because (I think) we'd have to sign each DLL and signing costs money. We can use static linkage with a dynamically linked MSVC runtime so we only have one DLL to sign.

Ref: #49404

What changes are included in this PR?

Updates to CMake and CI for the build to allow static linkage with dynamic MSVC runtime (x64-windows-static-md).

Are these changes tested?

Yes.

Are there any user-facing changes?

No.

@github-actions

Copy link
Copy Markdown

Thanks for opening a pull request!

If this is not a minor PR. Could you open an issue for this pull request on GitHub? https://github.com/apache/arrow/issues/new/choose

Opening GitHub issues ahead of time contributes to the Openness of the Apache Arrow project.

Then could you also rename the pull request title in the following format?

GH-${GITHUB_ISSUE_ID}: [${COMPONENT}] ${SUMMARY}

or

MINOR: [${COMPONENT}] ${SUMMARY}

See also:

@amoeba

amoeba commented Mar 24, 2026

Copy link
Copy Markdown
Member Author

I have this building locally. Before this PR:

Dump of file release\arrow_flight_sql_odbc.dll

File Type: DLL

  Image has the following dependencies:

    arrow_flight_sql.dll
    arrow_flight.dll
    WSOCK32.dll
    WS2_32.dll
    CRYPT32.dll
    GDI32.dll
    arrow_compute.dll
    arrow.dll
    abseil_dll.dll
    boost_locale-vc143-mt-x64-1_90.dll
    KERNEL32.dll
    USER32.dll
    COMDLG32.dll
    MSVCP140.dll
    MSVCP140_CODECVT_IDS.dll
    VCRUNTIME140.dll
    VCRUNTIME140_1.dll
    api-ms-win-crt-runtime-l1-1-0.dll
    api-ms-win-crt-heap-l1-1-0.dll
    api-ms-win-crt-string-l1-1-0.dll
    api-ms-win-crt-stdio-l1-1-0.dll
    api-ms-win-crt-locale-l1-1-0.dll
    api-ms-win-crt-convert-l1-1-0.dll
    api-ms-win-crt-filesystem-l1-1-0.dll
    api-ms-win-crt-time-l1-1-0.dll

After:

Dump of file cpp\build\release\arrow_flight_sql_odbc.dll

File Type: DLL

  Image has the following dependencies:

    ADVAPI32.dll
    IPHLPAPI.DLL
    WSOCK32.dll
    GDI32.dll
    WS2_32.dll
    CRYPT32.dll
    KERNEL32.dll
    USER32.dll
    COMDLG32.dll
    bcrypt.dll
    dbghelp.dll

@amoeba amoeba force-pushed the flight-sql-odbc-static branch from 74eb8f6 to 3320df2 Compare March 29, 2026 18:29
@amoeba amoeba force-pushed the flight-sql-odbc-static branch from ca55ec8 to 7782c69 Compare April 11, 2026 05:32
@amoeba amoeba changed the title DRAFT: set up static build of ODBC FlightSQL driver GH-49538: [C++][FlightRPC][ODBC] Use static linkage in Windows FlightSQL ODBC driver Apr 18, 2026
@github-actions

Copy link
Copy Markdown

⚠️ GitHub issue #49538 has been automatically assigned in GitHub to PR creator.

@lidavidm lidavidm left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread cpp/src/arrow/flight/sql/odbc/tests/odbc_test_suite.cc Outdated
@github-actions github-actions Bot added awaiting merge Awaiting merge awaiting review Awaiting review and removed awaiting review Awaiting review labels Apr 19, 2026
@github-actions github-actions Bot added awaiting committer review Awaiting committer review and removed awaiting review Awaiting review awaiting merge Awaiting merge labels Apr 20, 2026

@alinaliBQ alinaliBQ left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@amoeba I see the branch is about a week old, could we rebase on the latest main? I see there are no conflicts, but I am curious to see if the test code changes at odbc_impl in this PR can incidentally help with #49767 (not required for this PR)

I have tested the ODBC MSI installer manually, and can confirm I am able to retrieve data from Power BI using the installer and static linkage ODBC.

Comment thread cpp/src/arrow/flight/sql/odbc/tests/odbc_test_suite.cc Outdated

@alinaliBQ alinaliBQ left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was able to build and test release ODBC on my Windows machine locally. But I am getting this error on debug:

I have built from scratch and kept getting this error after several tries. I think this error was from a pre-existing issue where static Debug mode on MSVC was not supported.

absl_synchronization.lib(mutex.cc.obj) : error LNK2005: "private: void __cdecl absl::lts_20250814::Mutex::Dtor(void)" (?Dtor
@Mutex@lts_20250814@absl@@AEAAXXZ) already defined in arrow_flight_static.lib(grpc_client.obj) [C:\path\to\arrow\cpp\static-debug-build\src\arrow\flight\sql\arrow-flight-sql-test.vcxproj]
C:\path\to\arrow\cpp\static-debug-build\debug\Debug\arrow-flight-sql-test.exe : 
fatal error LNK1169: one or more multiply defined symbols found [C:\path\to\arrow\cpp\static-debug-build\src\arrow\flight\sql\arrow-flight-sql-test.vcxproj]
  Building Custom Rule C:/path/to/arrow/cpp/src/arrow/flight/CMakeLists.txt
  test_server.cc
absl_synchronization.lib(mutex.cc.obj) : error LNK2005: "private: void __cdecl absl::lts_20250814::Mutex::Dtor(void)" (?Dtor
@Mutex@lts_20250814@absl@@AEAAXXZ) already defined in arrow_flight_static.lib(protocol_grpc_internal.obj) [C:\path\to\arrow\cpp\static-debug-build\src\arrow\flight\flight-test-server.vcxproj]
C:\path\to\arrow\cpp\static-debug-build\debug\Debug\flight-test-server.exe : fatal error
LNK1169: one or more multiply defined symbols found [C:\path\to\arrow\cpp\static-debug-build\src\arrow\flight\flight-test-server.vcxproj]

(and many errors that look similar)

Since #48964 changes absl bundling, maybe rebasing to main will fix this error on debug static builds.

@amoeba amoeba force-pushed the flight-sql-odbc-static branch from 1f8181f to 56ca928 Compare April 21, 2026 23:52
@amoeba

amoeba commented Apr 21, 2026

Copy link
Copy Markdown
Member Author

Thanks for testing @alinaliBQ. I just rebased and I'll try a debug build locally and report back.

@amoeba amoeba force-pushed the flight-sql-odbc-static branch from 2a77336 to 710ed57 Compare June 9, 2026 22:33
@github-actions github-actions Bot added awaiting change review Awaiting change review and removed awaiting changes Awaiting changes labels Jun 9, 2026
Copilot AI review requested due to automatic review settings June 9, 2026 22:44

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 11 comments.

Comment on lines 234 to +238
void ODBCTestBase::TearDown() {
ASSERT_EQ(SQL_SUCCESS, SQLFreeHandle(SQL_HANDLE_STMT, stmt));
if (connected) {
ASSERT_EQ(SQL_SUCCESS, SQLFreeHandle(SQL_HANDLE_STMT, stmt));
}
}
Comment on lines +240 to +261
void ODBCTestBase::TearDownTestSuite() {
if (connected) {
// WORKAROUND GH-49585: Skip Disconnect() to avoid segfault when run through CTest
//
// When tests are run through CTest (but NOT when run directly from cmd.exe),
// SQLFreeHandle(SQL_HANDLE_ENV) crashes during cleanup. The crash occurs only with
// static linkage (ARROW_TEST_LINKAGE=static) and happens while freeing the ODBC
// environment handle, which triggers cleanup of statically-linked gRPC/Flight
// resources.
//
// Root cause appears to be CTest's process management (signal handling, I/O
// redirection, or environment differences) interfering with gRPC cleanup during
// static destruction.
//
// This workaround leaks the ODBC handles but allows tests to complete successfully.
// A proper fix would require ensuring gRPC is kept alive until all ODBC handles are
// freed, or switching to dynamic linkage for tests.
//
// Disconnect();
connected = false;
}
}
@@ -91,8 +102,6 @@ add_arrow_lib(arrow_flight_sql_odbc
${ARROW_FLIGHT_SQL_ODBC_SRCS}
DEFINITIONS
UNICODE
Comment on lines +120 to +126
if(WIN32
AND CMAKE_BUILD_TYPE STREQUAL "Debug"
AND ARROW_FLIGHT_TEST_LINKAGE STREQUAL "static")
foreach(LIB_TARGET ${ARROW_FLIGHT_SQL_ODBC_LIBRARIES})
target_link_options(${LIB_TARGET} PRIVATE "/FORCE:MULTIPLE")
endforeach()
endif()
Comment on lines +210 to +219
if(WIN32
AND CMAKE_BUILD_TYPE STREQUAL "Debug"
AND ARROW_FLIGHT_TEST_LINKAGE STREQUAL "static")
if(TARGET arrow_odbc_spi_impl_cli)
target_link_options(arrow_odbc_spi_impl_cli PRIVATE "/FORCE:MULTIPLE")
endif()
if(TARGET arrow-odbc-spi-impl-test)
target_link_options(arrow-odbc-spi-impl-test PRIVATE "/FORCE:MULTIPLE")
endif()
endif()
Comment on lines +98 to +104
if(WIN32
AND CMAKE_BUILD_TYPE STREQUAL "Debug"
AND ARROW_FLIGHT_TEST_LINKAGE STREQUAL "static")
foreach(LIB_TARGET ${ARROW_FLIGHT_SQL_LIBRARIES})
target_link_options(${LIB_TARGET} PRIVATE "/FORCE:MULTIPLE")
endforeach()
endif()
Comment on lines +197 to +205
if(WIN32
AND CMAKE_BUILD_TYPE STREQUAL "Debug"
AND ARROW_FLIGHT_TEST_LINKAGE STREQUAL "static")
foreach(TEST_TARGET arrow-flight-sql-test flight-sql-test-server flight-sql-test-app)
if(TARGET ${TEST_TARGET})
target_link_options(${TEST_TARGET} PRIVATE "/FORCE:MULTIPLE")
endif()
endforeach()
endif()
Comment on lines +249 to +255
if(WIN32
AND CMAKE_BUILD_TYPE STREQUAL "Debug"
AND ARROW_FLIGHT_TEST_LINKAGE STREQUAL "static")
foreach(LIB_TARGET ${ARROW_FLIGHT_LIBRARIES})
target_link_options(${LIB_TARGET} PRIVATE "/FORCE:MULTIPLE")
endforeach()
endif()
Comment on lines +404 to +418
if(WIN32
AND CMAKE_BUILD_TYPE STREQUAL "Debug"
AND ARROW_FLIGHT_TEST_LINKAGE STREQUAL "static")
set(FLIGHT_TEST_EXES
arrow-flight-internals-test
arrow-flight-test
flight-test-server
arrow-flight-perf-server
arrow-flight-benchmark)
foreach(test_exe ${FLIGHT_TEST_EXES})
if(TARGET ${test_exe})
target_link_options(${test_exe} PRIVATE "/FORCE:MULTIPLE")
endif()
endforeach()
endif()
Comment on lines +600 to +603
ARROW_DEPENDENCY_USE_SHARED: OFF
ARROW_MIMALLOC: OFF
ARROW_TEST_LINKAGE: shared
ARROW_USE_STATIC_CRT: OFF
@amoeba

amoeba commented Jun 9, 2026

Copy link
Copy Markdown
Member Author

I rebased and will work on cleaning this up this week.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants